package com.tim.arc.spring;

import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

import javax.servlet.Filter;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;

/**
 * @author litianlin
 * @date 2023/11/23 10:29
 * @description: springboot学习
 */
public class SpringBootInfo {
    public static void main(String[] args) throws Exception {
        spi();
    }

    /**
     *
     */
    public static void spi() throws IOException {
        /** step，classLoader*/
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        systemClassLoader.getResources("");
        // 各classLoader加载路径
        System.out.println(int[].class.getClassLoader());
        System.out.println(System.getProperty("sun.boot.class.path"));
        System.out.println(System.getProperty("java.ext.dirs"));
        System.out.println(System.getProperty("java.class.path"));

        /** step，springboot spi*/
        List<SpringApplicationRunListener> listeners = SpringFactoriesLoader.loadFactories(SpringApplicationRunListener.class, null);
        {
            // 加载 META-INF/spring.factories
            Enumeration<URL> resources = SpringBootInfo.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
            while (resources.hasMoreElements()){
                System.out.println(resources.nextElement());
            }

            // 类加载

            // 对象实例化


        }

    }

    public static void reqRespExtension() {
        Filter filter;//过滤器
        HandlerInterceptor hi;//拦截器。@ResponseBody，返回前端、postHandle为异步

        RequestBodyAdvice advice;//入参处理，before、after入参解析
        HandlerMethodArgumentResolver resolver;//入参解析，requestBody构建对象；遍历执行

        HandlerMethodReturnValueHandler handler;//选择性响应属性定制化处理，执行第一个匹配
        {
            /*
            Controller Method Return Value
                   │
                   ▼
            HandlerMethodReturnValueHandler （决定怎么处理返回值，执行第一个匹配）
                   │
                   ▼
            ResponseBodyAdvice.beforeBodyWrite （可修改返回值；遍历）
                   │
                   ▼
            HttpMessageConverter.write() （序列化为 JSON / XML 等）
                   │
                   ▼
            写入 HttpServletResponse.getOutputStream() / getWriter()

            * */
            ResponseBodyAdvice advice2;//HttpMessageConverter前响应定制化
            HttpMessageConverter msgConverter;//入参反序列化、响应序列化，执行第一个匹配
            HttpMessageConverters converters;//配置自定义converter，未配置对应mediaType时使用默认值
        }


        /*
        *
        * */
        WebMvcConfigurer config;
    }

    public static void aop() {
        MethodInterceptor mi;

    }

}
